package initialize

import (
	"github.com/go-playground/locales/zh"
	ut "github.com/go-playground/universal-translator"
	"github.com/go-playground/validator/v10"
	translations "github.com/go-playground/validator/v10/translations/zh"
	"interview/pkg/global"
)

// Validator 初始化校验器
func Validator() {
	// 实例化需要转换的语言
	chinese := zh.New()
	uni := ut.New(chinese, chinese)
	trans, _ := uni.GetTranslator("zh")
	v := validator.New()

	// 注册转换的语言为默认语言
	_ = translations.RegisterDefaultTranslations(v, trans)

	global.Validate = v
	global.Translator = trans
	global.Logger.Debug("初始化validator完毕")
}
